#include "stdafx.h"
#include <utilex/getpath.hpp>



int main_t(HINSTANCE hInstance,int argc, TCHAR* argv[])
{
	int		iRes = 0;
	do {
		HRESULT hr	=	S_OK;
		CComLoader loader;
		_lComPtr<IComEnv>	pIComEnv;
		tstring stringcomenv;
		tstring stringpath = GetCurrentRunPath(NULL);
		tstring stringconfig;
		stringpath		+=	path_slash;
		stringcomenv	=	stringpath;
		stringconfig	=	stringpath;
		stringconfig	+=	_T("mainmoduleconfig.json");
		stringcomenv	+=	ModNameToModPath(_T("comenv"));

		iosprintf("load config file");
		BOOL bRet		=	loader.LoadCom(stringcomenv.c_str());	

		pIComEnv = INULL;
		retrtnpv(bRet != TRUE, 1)

		hr = loader.CreateInstance(CLSID_ComEnv,INULL,INULL,_uuidof(IComEnv),(void**)&pIComEnv.m_p);

		retrtnpv(hr != S_OK, 1)
		retrtnpv(pIComEnv == INULL, 1)

		iosprintf("pIComEnv is NO NULL");
		hr = pIComEnv->InitEnv(hInstance, stringconfig.c_str());
		retrtnpv(hr != S_OK,0)
		iosprintf("run comenv");

		//cmd line argc CommandLineToArgvW(GetCommandLineW(), &nArgs);
		iRes = pIComEnv->Run();

	} while (iRes == 1000);

	iosprintf("run end");
	return 1;
}


#if (TARGET_OS == OS_POSIX)
	int main_t(int argc,char* argv[])
	{
		HINSTANCE hInstance = NULL;
		return domain(hInstance, argc, argv);
	}
#elif (TARGET_OS == OS_MAC)


#elif  (TARGET_OS == OS_WINDOWS)
int WINAPI WinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR lpCmdLine,
	int nCmdShow) {

	int iRet = 0;
	int nArgs = 0;
	LPWSTR* szArglist = NULL;
	szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
	iRet = main_t(hInstance, nArgs, szArglist);
	LocalFree(szArglist);
	return 1;
}
#endif


